Add index to sliding_sync_connection_lazy_members on connection_position#19923
Add index to sliding_sync_connection_lazy_members on connection_position#19923erikjohnston wants to merge 1 commit into
sliding_sync_connection_lazy_members on connection_position#19923Conversation
This speeds up the cascading delete from `sliding_sync_connection_positions`, which without an index on `connection_position` requires a sequential scan of the whole table for each deleted position. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sliding_sync_connection_lazy_members on connection_position
| @@ -0,0 +1 @@ | |||
| Add an index to `sliding_sync_connection_lazy_members` to speed up deleting old sliding sync connection positions. | |||
There was a problem hiding this comment.
This speeds up the cascading delete from
sliding_sync_connection_positions, which without an index onconnection_positionrequires a sequential scan of the whole table for each deleted position.
We already have an index on connection_key and we expect only two entries at a time.
Seems weird that an index would help.
There was a problem hiding this comment.
sliding_sync_connection_lazy_members has a foreign key on connection_position, and so when we delete from sliding_sync_connection_positions postgres has to look for any matches on sliding_sync_connection_lazy_members.connection_position. It's not smart enough to be able to understand that it can lookup (connection_key, connection_position) (as that is not the FK)
There was a problem hiding this comment.
Argh, this is a wasteful index but I see 👍
|
|
||
| self.db_pool.updates.register_background_index_update( | ||
| update_name="sliding_sync_connection_lazy_members_conn_pos_idx", | ||
| index_name="sliding_sync_connection_lazy_members_conn_pos_idx", |
There was a problem hiding this comment.
Sucks that we already have sliding_sync_connection_lazy_members_pos_idx with a similar name already
| @@ -0,0 +1 @@ | |||
| Add an index to `sliding_sync_connection_lazy_members` to speed up deleting old sliding sync connection positions. | |||
There was a problem hiding this comment.
Argh, this is a wasteful index but I see 👍
This speeds up the cascading delete from
sliding_sync_connection_positions, which without an index onconnection_positionrequires a sequential scan of the whole table for each deleted position.